// task_transaction_record_cell.dart
import 'package:flutter/material.dart';
import '../../../repository/model/task_transaction_record_model.dart';

class TaskTransactionRecordCell extends StatelessWidget {
  final TaskTransactionRecordModel model;
  final bool showBottomLine;

  const TaskTransactionRecordCell({
    Key? key,
    required this.model,
    this.showBottomLine = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final hasStatusDescription = model.statusDescription != null &&
        model.statusDescription!.isNotEmpty;

    return Container(
      height: 58,
      padding: const EdgeInsets.symmetric(horizontal: 15),
      decoration: BoxDecoration(
        border: showBottomLine
            ? const Border(
          bottom: BorderSide(
            color: Color(0xFFEEEEEE),
            width: 0.5,
          ),
        )
            : null,
      ),
      child: Row(
        children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  model.descriptionStr ?? '',
                  style: const TextStyle(
                    fontSize: 15,
                    color: Color(0xFF2D2D2D),
                    fontWeight: FontWeight.w500,
                  ),
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
                const SizedBox(height: 2),
                Text(
                  _getTimeText(),
                  style: const TextStyle(
                    fontSize: 11,
                    color: Color(0xFFAAAAAA),
                  ),
                ),
                if (hasStatusDescription) ...[
                  const SizedBox(height: 2),
                  Text(
                    model.statusDescription!,
                    style: const TextStyle(
                      fontSize: 11,
                      color: Color(0xFFAAAAAA),
                    ),
                  ),
                ],
              ],
            ),
          ),
          Container(
            width: 80,
            alignment: Alignment.centerRight,
            child: Text(
              model.amount ?? '',
              style: const TextStyle(
                fontSize: 15,
                color: Color(0xFFFF4974),
                fontWeight: FontWeight.w500,
              ),
              textAlign: TextAlign.right,
            ),
          ),
        ],
      ),
    );
  }

  String _getTimeText() {
    return model.exchangeDay ?? model.createTime ?? '';
  }
}